<template>
    <view class="page">
        <water-mark :meta="meta"></water-mark>
        <view>
            <rich-text class="content" :nodes="richContentStr"></rich-text>
        </view>
    </view>
</template>

<script>
    import SearchService from '@/services/search/index'
    import uniIcon from "@/components/uni-icon/uni-icon.vue"

    const searchService = new SearchService()
    import mixins from '@/mixins/index';
    import {richContent} from '@/utils/index'

    export default {
        mixins: [mixins],
        components: {uniIcon},
        data() {
            return {
                richContentStr: '',
                introduce: '',
                lawDetail: '',
                isShow: false,
            }
        },
        onLoad(options) {
            let id = options.id;
            let keyword = options.keyword;
            if (undefined !== id || undefined !== keyword) {
                searchService.searchLawInfo(id, keyword).then(response => {
                    if (response.success) {
                        const {parentId, lawDetail, lawTitle} = response.result;
                        this.lawDetail = lawDetail;
                        const content = richContent(lawDetail);
                        this.richContentStr = content;
                        searchService.searchDetail(options.id).then(response => {
                            if (response.success) {
                                const {introduce} = response.result;
                                this.introduce = introduce;
                            }
                        });
                    }
                });
            }
        },
		onUnload() {
			uni.hideLoading();
		},
        methods: {
            changeBtn(colorValue) {
                let pages = getCurrentPages();
                let page = pages[pages.length - 1];
                // #ifdef APP-PLUS
                let currentWebview = page.$getAppWebview();
                let titleObj = currentWebview.getStyle().titleNView;
                if (!titleObj.buttons) {
                    return;
                }
                titleObj.buttons[0].text = colorValue;
                // "\ue653";
                currentWebview.setStyle({
                    titleNView: titleObj
                });
                // #endif
            },
            queryLawInfo() {
                if (!this.isShow) {
                    const content = richContent(this.introduce);
                    this.richContentStr = content;
                    this.changeBtn("\ue653");
                } else {
                    const content = richContent(this.lawDetail);
                    this.richContentStr = content;
                    this.changeBtn("\ue632");
                }
                this.isShow = !this.isShow;
				if (uni.getSystemInfoSync().platform == "android") {
					setTimeout(()=>{
						uni.hideLoading();
					},1000);
				}else{
					uni.hideLoading();
				}
            }
        },
	
        onNavigationBarButtonTap(e) {
			uni.showLoading({
				title:'加载中'
			})
            this.queryLawInfo();


        },
    }
</script>

<style lang="scss" scoped>
    .page {
        padding-left: 20 upx;
        padding-right: 20 upx;
		margin-left: 30upx;
		margin-right: 30upx;
    }

    .content {
        // padding: 20upx;
        font-size: 14px;
    }
</style>
